This simple HTML page is executing all functionality within the hosting browser. A real web page needs to post back to a resource on the web server, passing all of the input data at the same time. Once the server side resource receives this data, it can use it to build a proper HTTP response.
The action attribute on the opening <form> tag specifies the recipient of the incoming form data. Possible receivers include mail servers, other HTML files on the web server, a classic (COM-based) Active Server Pages (ASP) file, an ASP.NET web page, and so forth.
Beyond the action attribute, you will also likely have a submit button, which when clicked, will transmit the form data to the web application via an HTTP request. You have no need to do so for this example; however, here is an update to the default.htm file, specifying the following attribute in the opening <form> tag:
<form id="defaultPage" action="http://localhost/Cars/ClassicAspPage.asp" method="GET"> <input id="btnPostBack" type="submit" value="Post to Server!"/> ... </form>
When the submit button for this form is clicked, the form data is sent to the ClassicAspPage.asp at the specified URL. When you specify method="GET" as the mode of transmission, the form data is appended to the query string as a set of name/value pairs separated by ampersands. You may have seen this sort of data in your browser before, for example:
http://www.google.com/search?hl=en&source=hp&q=vikings&cts=1264370773666&aq=f&aql=&aqi=g1g-z1g1g-z1g1g-z1g4&oq=
The other method of transmitting form data to the web server is to specify method="POST":
<form id="defaultPage" action="http://localhost/Cars/ClassicAspPage.asp" method = "POST"> ... </form>
In this case, the form data is not appended to the query string. Using POST, the form data is not directly visible to the outside world. More important, POST data does not have a character-length limitation; many browsers have a limit for GET queries.
When you are building ASP.NET based web sites, the framework will take care of the posting mechanics on your behalf. One of the many benefits of building a web site using ASP.NET is that the programming model layers on top of standard HTTP Request/Response an event driven system. Thus, rather than manually setting an action attribute and defining an HTML submit button, you can simply handle events on the ASP.NET web controls using standard C# syntax.
Using this event driven model, you can very easily post back to the web server using a large number of controls. If you require, you can post back to the web server if the user clicks on a radio button, an item in a list box, a day on a calendar control, and so on. In each case, you simply handle the correct event, and the ASP.NET runtime will automatically emit back the correct HTML posting data.
Source Code The SimpleWebPage website is included under the Chapter 32 subdirectory.